package com.emeraldparser.grammar;

import com.emeraldparser.symbol.SymbolClass.State;
import com.emeraldparser.util.HashCodes;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;

public final class RightState implements State {
	
	private final Rule rule;
	private final State rightState;
	private final transient int hashCode;

	public RightState(Rule rule, State rightState) {
		this.rule = Preconditions.checkNotNull(rule, "Rule must not be null");
		this.rightState = Preconditions.checkNotNull(rightState, "Right state must not be null");
		this.hashCode = HashCodes.classSpecificHashCode(RightState.class, rule, rightState);
	}

	public Rule getRule() {
		return rule;
	}

	public State getRightState() {
		return rightState;
	}

	@Override
	public String toString() {
		return rule.getLeftSymbolClass() + " = " + rightState;
	}
	
	@Override
	public int hashCode() {
		return hashCode;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		RightState other = (RightState) obj;
		
		return Objects.equal(rule, other.rule)
		    && Objects.equal(rightState, other.rightState);
	}

}
